//
//  MYXmypublishViewModel.m
//  meiyinxiang
//
//  Created by 陈李飞 on 2017/11/28.
//  Copyright © 2017年 hbjApple. All rights reserved.
//

#import "MYXmypublishViewModel.h"
#import "MYXmypublishModel.h"
#import "NSString+Additions.h"
@implementation MYXmypublishViewModel
- (void)loadmypublish :(int)PageIndex
            WithResult:(pulishBlock)result{
    if (self.publishArray == nil) {
        self.publishArray = [NSMutableArray array];
    }
    if (PageIndex == 1){
        [self.publishArray removeAllObjects];
    }
    [[MYXHttpManager shared]mypublish:PageIndex withResult:^(BOOL success, NSString *msg, NSArray *arrays) {
        if (success) {
            if (arrays.count>0) {
                for (MYXmypublishModel *model in arrays) {
                    if (model.file.length>0) {
                        model.height = 60+20;
                    }else{
                       CGSize contentSize = [model.content sizeWithConstrainedToWidth:WIDTH-100 fromFont:[UIFont systemFontOfSize:11] lineSpace:3 numberOfLines:0];
                        if (contentSize.height>=50) {
                             model.height = 50+20;
                        }else{
                             model.height =25+20;
                        }
                    }
                    [self.publishArray addObject:model];
                }
                result(YES);
            }else{
                result(NO);
            }
        }else{
            result(NO);
        }
       
    } errorResult:^(NSError *enginerError) {
         result(NO);
    }];
}
@end
